<?php
class Mageex_RelatedProduct_Block_RelatedProduct extends Mage_Catalog_Block_Product_Abstract
{
	public function __construct() 
	{	
		$this->setTemplate('relatedproduct/relatedproduct.phtml'); 
    }
	public function getBlocks()
	{
		$condition = $this->getCondition();
		
		$blocks = Mage::helper('relatedproduct')->getBlocks($condition['type'], $condition['page']);
		
		return $blocks;
	}	
	public function strToArray($str, $limit)
	{
		
		$arr = explode(',', $str);
		$arrResult = array();
		$length = count($arr);
		if($length >$limit){
			$arrRands = array_rand($arr, $limit);
			foreach($arrRands as $rand){
				$arrResult[] = $arr[$rand];
			}
			return $arrResult;
		}
		$arrResult = array();
		$arrRands =array_rand($arr, $length);
		foreach($arrRands as $rand){
			$arrResult[] = $arr[$rand];
		}
		return $arrResult;
	}
	public function getProductInfor($id)
	{
		return Mage::getModel('catalog/product')->load($id);
	}
}